﻿// <copyright file="FourByteSensorDataTelegram.cs" company="Hallvard Korsgaard">
//  Microsoft Public License (Ms-PL). See license details here: http://enoceannet.codeplex.com/license
// </copyright>
// <author>Hallvard Korsgaard</author> 

namespace EnOcean.Radio.Sensor
{
  using System;

  /// <summary>
  /// Represents a 4 byte data telegram (ORG = 0x07).
  /// </summary>
  [Serializable]
  public class FourByteSensorDataTelegram : FourByteSensorTelegram
  {
    /// <summary>
    /// Gets or sets data byte 0.
    /// </summary>
    public byte Data0
    {
      get;
      set;
    }

    /// <summary>
    /// Gets or sets data byte 1.
    /// </summary>
    public byte Data1
    {
      get;
      set;
    }

    /// <summary>
    /// Gets or sets data byte 2.
    /// </summary>
    public byte Data2
    {
      get;
      set;
    }

    /// <summary>
    /// Gets or sets data byte 3.
    /// </summary>
    public byte Data3
    {
      get;
      set;
    }

    /// <summary>
    /// Gets a value indicating whether the LRN button was pressed.
    /// </summary>
    public bool IsLearnButtonPressed
    {
      get
      {
        return (this.Data0 & 0x08) == 0;
      }
    }

    /// <summary>
    /// Creates the byte format of the message.
    /// </summary>
    /// <param name="message">A byte array of length 14 to hold the message contents.</param>
    protected internal override void CreateMessage(byte[] message)
    {
      base.CreateMessage(message);
      message[4] = this.Data3; // Data 3
      message[5] = this.Data2; // Data 2
      message[6] = this.Data1; // Data 1
      message[7] = this.Data0; // Data 0
    }
  }
}
